<#-- 包含其他文件的内容 -->
<#include "../common/header.ftl"/>
<script>
    $(function () {
        // 下拉列表值改变事件
        $("select[name='strategyId']").change(function () {
            // 提交表单
            $("#searchForm").submit();
        });
        // 新增OR修改
        $(".inputBtn").click(function () {
            // 清空模态框
            $("#editForm").get(0).reset();
            // 获取json数据
            var josn = $(this).data("json");
            // console.log(josn);
            // 将数据设置到模态框中
            if (josn) {
                $("#editForm input[name='id']").val(josn.id);
                $("#editForm input[name='name']").val(josn.name);
                $("#strategyId").val(josn.strategyId);
                $("#editForm input[name='sequence']").val(josn.sequence);
                // 注意后台的数据状态是布尔类型，界面是字符串类型
                $("#editForm select[name='state']").val(josn.state + '');
                // 修改时，将所属攻略输入框设置为不可修改状态
                $("#strategyId").attr("disabled", true);
            } else {
                // 修改时，将所属攻略输入框恢复可选择状态
                $("#strategyId").attr("disabled", false);
                // 新增时，要将当前选择的所属攻略设置到模态框
                $("#strategyId").val($("#searchForm select[name='strategyId']").val());
            }
            // 显示模态框
            $("#inputModal").modal("show");
        });

        // 提交大攻略表单
        $(".submitBtn").click(function () {
            // 提交前移除disabled属性
            $("#strategyId").attr("disabled", false);
            $("#editForm").ajaxSubmit(function (data) {
                doSuccess(data);
            });
        });
    });
</script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="strategyCatalog"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">攻略分类管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyCatalog/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>所属攻略:</label>
                    <select class="form-control" name="strategyId">
                        <option value="-1">所有攻略</option>
                        <#list strategys as s>
                            <option value="${s.id}">${s.title}</option>
                        </#list>
                    </select>
                    <script>
                        $("select[name='strategyId']").val(${(qo.strategyId)!});
                        // 判断是否是查询所有
                        $(function () {
                            if ($("select[name='strategyId']").val() == -1) {
                                // 移除点击事件
                                $("#save").unbind("click");
                                // 设置文字样式
                                $("#save").html("<span class=\"glyphicon glyphicon-hand-left\"></span> 请选择攻略进行添加");
                            }
                        });
                    </script>
                </div>
                <#-- <button id="btn_query" class="btn btn-default">
                     <span class="glyphicon glyphicon-search"></span> 查询
                 </button>-->
                <a role="button" class="btn btn-success inputBtn" id="save">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>分类名称</th>
                    <th>所属攻略</th>
                    <th>排序</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.name}</td>
                        <td>${entity.strategy.title}</td>
                        <td>${entity.sequence}</td>
                        <td>${entity.state?string("启用","禁用")}</td>
                        <td>
                            <a class="btn btn-info btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/strategyCatalog/saveOrUpdate.do" method="post" id="editForm">

                    <input type="text" name="id" hidden>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">分类名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略：</label>
                        <div class="col-sm-6">
                            <select class="form-control" id="strategyId" name="strategy.id">
                                <#list strategys as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="sequence">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state">
                                <option value="true">启用</option>
                                <option value="false">禁用</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>


</body>
</html>